<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/* 	Class Name	: master data general
	Author 		: Iswan Putera S.Kom
	Version		: 2.0
	Date		: 09 May 2013
*/

class General extends CI_Controller
{
		function __construct()
	{
		parent::__construct();	
		$this->load->model('main_model');
		$this->load->library('zetro_auth');
		//force_ssl();
	}
	//master jabatan karyawan
	function jabatan()
	{
		//load view
		$data=array();
		//menu header
		$data['tab_header']=$this->zetro_form->generate_tab_header('Data Jabatan Koperasi');
		//generate form popup modal add new jabatan
		$this->zetro_form->frm_file('asset/frm/zetro_master.frm');
		$this->zetro_form->section('jabatan');
		$this->zetro_auth->menus('data_jabatan_koperasi');
		$this->zetro_form->buttons(($this->zetro_auth->cek_oto('c')!='')?true:false);
		$data['modal']=$this->zetro_form->dialog($this->zetro_form->frm_std('frm1'),"Add new jabatan");
		//generate list data lokasi
		$content='';//$this->get_list_jabatan();
		$this->zetro_form->section('listjabatan');
		$this->zetro_form->action_col(true);
		$content.="";//$this->zetro_form->DataNotFound($lst_usr,4);
		$this->zetro_form->tabel_content($content);
		$data['list']=$this->zetro_form->list_std();
		//send data to view
		$this->load->view('admin/header');
		$this->load->view('administration/jabatan',$data);
		$this->load->view('admin/footer');
		
	}
	function set_jabatan()
	{
		//simpan data jabatan baru
		$data=array();
		$data['id_jab']		=empty($_POST['id_jab'])?'0':$_POST['id_jab'];
		$data['id_jabatan']	=empty($_POST['id_jabatan'])?'':$_POST['id_jabatan'];
		$data['nm_jabatan']	=addslashes($_POST['nm_jabatan']);
		$data['stat_jabatan']=empty($_POST['stat_jabatan'])?'Y':$_POST['stat_jabatan'];
		$this->main_model->prepared_data('jabatan',$data);
		echo success($this->main_model->set_data());
	}
	
	function get_detail_jabatan()
	{
		//get detail data jabatan for update data
		$data=array();
		$id=$_POST['id'];
		$this->main_model->table_name('jabatan');
		$this->main_model->set_methods('select');
		$this->main_model->query();
		$this->main_model->where(array('id_jab'=>$id));
		$data=$this->main_model->set_data();
		echo json_encode($data[0]);	
	}
	
	function get_list_jabatan()
	{
		//show list data jabatan
		$content='';$i=0;$lst_usr=array();
		$ordby=empty($_POST['ordby'])?'id_jabatan':$_POST['ordby'];
		$this->main_model->table_name('v_jabatan_kop');
		$this->main_model->query();
		$this->main_model->orderby($ordby);
		$this->main_model->set_methods('select_ordered');
		$lst_usr=$this->main_model->set_data();
		foreach($lst_usr as $r)
		{
			$i++;
			$this->zetro_auth->menus('data_jabatan_koperasi');
			$icon=($this->zetro_auth->cek_oto('e')!='')?
				  $this->zetro_form->z_icon($r->id_jab,array('cus-page-white-edit','cus-cross'),array('edit','deleted')):'';
			$content.=tr().td($i,false,'','','center').
					  td($r->id_jabatan).td($r->nm_jabatan).
					  td($icon,false,'','','center')._tr();
		}
			$content.=$this->zetro_form->DataNotFound($lst_usr,4);
			echo $content;
	}
	
	function deleted_jabatan()
	{
		$id=$_POST['id'];
		$this->main_model->table_name('jabatan');
		$this->main_model->set_methods('delete');
		$this->main_model->where(array('id_jab'=>$id));
		$this->main_model->set_data();	
	}
	
	//data jabatan karyawan
	function jab_karyawan()
	{
		//load view
		$data=array();
		//menu header
		$data['tab_header']=$this->zetro_form->generate_tab_header('Data Jabatan Karyawan');
		//generate form popup modal add new jabatan
		$this->zetro_form->frm_file('asset/frm/zetro_master.frm');
		$this->zetro_form->section('jabatan');
		$this->zetro_auth->menus('data_jabatan_karyawan');
		$this->zetro_form->AddFields("<input type='hidden' id='stat_jabatan' name='stat_jabatan' value='N'/>");
		$this->zetro_form->Modale('frm1');
		$this->zetro_form->buttons(($this->zetro_auth->cek_oto('c')!='')?true:false);
		$data['modal']=$this->zetro_form->dialog($this->zetro_form->frm_std('frm1'),"Add new jabatan");
		//generate list data lokasi
		$content='';//$this->get_list_jabatan();
		$this->zetro_form->section('listjabatan');
		$this->zetro_form->action_col(true);
		$content.="";//$this->zetro_form->DataNotFound($lst_usr,4);
		$this->zetro_form->tabel_content($content);
		$data['list']=$this->zetro_form->list_std();
		//send data to view
		$this->load->view('admin/header');
		$this->load->view('administration/jabatan_kar',$data);
		$this->load->view('admin/footer');
	}
	
	function get_list_jabatan_kar()
	{
		//show list data jabatan
		$content='';$i=0;$lst_usr=array();
		$ordby=empty($_POST['ordby'])?'id_jabatan':$_POST['ordby'];
		$this->main_model->table_name('v_jabatan_kar');
		$this->main_model->query();
		$this->main_model->orderby($ordby);
		$this->main_model->set_methods('select_ordered');
		$lst_usr=$this->main_model->set_data();
		foreach($lst_usr as $r)
		{
			$i++;
			$this->zetro_auth->menus('data_jabatan_koperasi');
			$icon=($this->zetro_auth->cek_oto('e')!='')?
				  $this->zetro_form->z_icon($r->id_jab,array('cus-page-white-edit','cus-cross'),array('edit','deleted')):'';
			$content.=tr().td($i,false,'','','center').
					  td($r->id_jabatan).td($r->nm_jabatan).
					  td($icon,false,'','','center')._tr();
		}
			$content.=$this->zetro_form->DataNotFound($lst_usr,4);
			echo $content;
	}
}
